<template>
    <el-row type="flex" justify="center">
        <el-form :model="user" label-width="80px">
            <el-form-item label="用户名">
                <el-input v-model="user.name"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="user.pass" type="password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-upload" @click="login" :loading="ui.loginLoading">登录</el-button>
            </el-form-item>
        </el-form>
    </el-row>
</template>

<script>
    export default {
        methods: {
            login () {
                this.$router.replace('/')
            }
        },
        data () {
            return {
                ui:{
                    loginLoading:false,
                },
                user: {
                    name:'',
                    pass:''
                }
            }
        },
        mounted(){
            this.$nextTick(()=>{
            })
        },
        methods:{
            async login(){
                if (this.user.name===''||this.user.pass==='')
                    return false;
                this.ui.loginLoading=true;

                const [res] =await this.$$post("/login",{
                    name:this.user.name,
                    pass:this.user.pass
                });
                this.ui.loginLoading=false;
                if (this.catchErr(res))
                    return false;
                this.jump('/home');
            }
        }
    }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
    .header{
        background-color: #409EFF;
        color: white;
    }
</style>